package com.xrz.sxm.aj.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.xrz.sxm.aj.adapter.GridViewAdapter;
import com.xrz.sxm.aj.base.BaseAct;
import com.xrz.sxm.aj.cons.BuWei;
import com.xrz.sxm.aj.entity_tab.DBHelps;
import com.xrz.sxm.aj.view.BuweiViewGroup;
import com.xrz.sxm.aj.view.BuweiViewGroup.onBuweiCliclListener;

import java.util.ArrayList;
import java.util.List;

public class Act_Buwei extends BaseAct implements OnItemClickListener,onBuweiCliclListener{
	/**部位选中的items*/
	@ViewInject(R.id.buwei_items)
	private BuweiViewGroup m_BuweiViewGroup;
	/**传过来的选中的部位*/
	private BuWei m_BuWei;
	/**适配器*/
	private GridViewAdapter m_Adapter;
	/**GrdiView*/
	@ViewInject(R.id.gridview)
	private GridView m_GridView;

	private DBHelps m_DbHelps;

	private List<String> m_Bings;
	@Override
	protected int setView() {
		return R.layout.layout_buwei;
	}

	@Override
	protected void init() {
		m_DbHelps = new DBHelps(ctx);
		m_Bings = new ArrayList<String>();
		m_Adapter = new GridViewAdapter(this,m_Bings);
		m_BuWei = (BuWei) getIntent().getSerializableExtra("data");
		m_BuweiViewGroup.setOnBuweiClickListener(this);
		m_BuweiViewGroup.setDefaultSelect(m_BuWei);
		m_GridView.setAdapter(m_Adapter);
		m_GridView.setOnItemClickListener(this);
	}

	@Override
	protected String setTopTitle() {
		return "按部位浏览";
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		startActivity(new Intent(this, Act_Detail.class).putExtra("data", m_Bings.get(arg2)));
	}



	@Override
	public void onBuweiCLick(BuWei buWei, String buweiName) {
		m_Bings.clear();
		m_Bings.addAll(m_DbHelps.getBingByBuwei(buweiName));
		m_Adapter.notifyDataSetChanged();
	}

}
